package com.alan.sso.client.controller;

import com.alan.sso.share.bean.SsoUser;
import com.alan.sso.share.utils.SsoSession;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

/**
 * @Auther: Alan liu
 * @Date: 2018/12/24 14:16
 * @Description: LoginController
 */
@Slf4j
@Controller
@RequestMapping("login")
public class LoginController {

    @RequestMapping(value = {"","login","index"})
    public String login(HttpServletRequest request, Model model) {
        SsoUser currentUser = SsoSession.getCurrentUser(request);
        if(currentUser != null){
            log.info("用户{}登录成功", currentUser.getUserName());
            model.addAttribute("user",currentUser);
            return "/html/index";
        }
        return "/html/unauthorized";
    }

}
